﻿using LD.Host;
using Newtonsoft.Json.Linq;
using System;

namespace LD.Tool
{
    public partial class ToolCopyVariableFrm : FrmToolBase
    {
        public ToolCopyVariableFrm()
        {
            InitializeComponent();
            this.Shown += ToolMesSharpFrm_Shown;
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void ToolMesSharpFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }

        private void Init()
        {
            foreach (var item in Cache.Var)
            {
                this.cob_cacheSource.Items.Add(item.Name);
                this.cob_cacheObj.Items.Add(item.Name);
            }

            if (TB_Tool.Param != null)
            {
                JObject param = JObject.Parse(TB_Tool.Param);
                if (param != null)
                {
                    this.cob_cacheSource.Text = param["Source"].ToString();
                    this.cob_cacheObj.Text = param["Target"].ToString();
                }
            }
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            JObject param = new JObject()
                {
                    { "Source",this.cob_cacheSource.Text},
                    { "Target",this.cob_cacheObj.Text},
                };

            TB_Tool.Param = param.ToString();
        }
    }
}
